package basicmorse;
import java.util.HashMap;
import java.util.Map;

public class MorseDecoder {
	public enum Token {
		DOT("."),
		DASH("-"),
		SHORT_PAUSE("#"),
		LONG_PAUSE(" ");
		
		private final String visible;
		
		Token(String humanVisible) {
			visible = humanVisible;
		}
		
		@Override
		public String toString() {
			return visible;
		}
	}
	
	public static final String BAD_MORSE = "%";
	
	private static String [][] morseLetters = {
			{".-",		"a"},
			{"-...",	"b"},
			{"-.-.",	"c"},
			{"-..",		"d"},
			{".",		"e"},
			{"..-.",	"f"},
			{"--.",		"g"},
			{"....",	"h"},
			{"..",		"i"},
			{".---",	"j"},
			{"-.-",		"k"},
			{".-..",	"l"},
			{"--",		"m"},
			{"-.",		"n"},		
			{"---",		"o"},
			{".--.",	"p"},
			{"--.-",	"q"},
			{".-.",		"r"},
			{"...",		"s"},
			{"-",		"t"},
			{"..-",		"u"},
			{"...-",	"v"},
			{".--",		"w"},
			{"-..-",	"x"},
			{"-.--",	"y"},
			{"--..",	"z"},
	};
		
	private Map<String, String> letterMap;
	
	public MorseDecoder() {
		letterMap = new HashMap<>();
		
		for(int i = 0; i < morseLetters.length; i++) {
			letterMap.put(morseLetters[i][0], morseLetters[i][1]);
		}
	}
	
	public String decode(String morseLetter) {
		String realLetter = letterMap.get(morseLetter);
		
		if(realLetter == null) {
			realLetter = BAD_MORSE;
		}
		
		return realLetter;
	}
}
